#e[Player]
#ScriptVersion[2]
#Menu[STATE]
#Image[.\s.png]
#Text[]
#ReplayName[th_psy]

script_player_main
{
	let current		=GetCurrentScriptDirectory();
	let imgpsy		=current~"psy.png";
	let imgrate		=current~"rate.png";
	let shot1		=current ~ "shot1.wav";
	let shotCount		=-1;
	let bNextShot		=false;
	let sw_shotCount	=-1;
	let sw_bNextShot	=false;
	let ix			=GetClipMinX;
	let mx			=GetClipMaxX;
	let iy			=GetClipMinY;
	let my			=GetClipMaxY;
	let S			=0;
	let sp			=0;
	let S1			=0;
	let swx			=0;
	let swy			=0;
	let sw_r		=0;
	let swa			=0;
	let swb			=0;
	let p1			=0;
	let p2			=0;
	let p3			=0;
	let p4			=0;
	let sw_g		=120;
	let AlphaCount		=255;
	let A1			=0;
	let B1			=0;
	let D1			=0;
	let k1			=0;
	let k2			=0;
	let k3			=0;
	let k4			=0;
	let moji		=0;
	let moji1		=0;
	let moji2		=0;
	let moji3		=0;
	let moji4		=0;
	let moji5		=0;
	let moji6		=0;
	let moji01		=0;
	let moji02		=0;
	let moji03		=0;
	let moji04		=0;
	let moji05		=0;
	let moji06		=0;
	let moji11		=0;
	let moji12		=0;
	let moji13		=0;
	let moji21		=0;
	let moji22		=0;
	let moji23		=0;
	let dc			=0;
	let ppp			=0;
	let t_ppp		=0;
	let p			=0;
	let p_m			=0;
	let jiki		=0;
	let JIKI		=0;
	let kaif		=0;
	let bk			=0;
	let NoShot		=0;
	let kntu		=0;

	@Initialize
	{	
		SetPlayerLifeImage(imgpsy, 1, 5, 49, 60);
		LoadGraphic(imgpsy);
		LoadGraphic(imgrate);
		LoadSE(shot1);
		//SetAutoEffect(false);
		SetRebirthFrame(0);
		LoadPlayerShotData(current~"psyShotData.txt");
		GetCommonData("jiki");
		GetCommonData("NoShot");
	}


		function RealToIntString(let num){
		if(num<0){num=0;}
		let stringarray=["0","1","2","3","4","5","6","7","8","9"];
		let lp=floor(log10(num))+1;
		let lp1=lp;
		if(lp<=0){result="0"}
		else{
		result = "";
		loop(lp){
		result=result~ stringarray[(num%(10^lp1)-num%(10^(lp1-1)))/(10^(lp1-1))];
		lp1--;
		}
		}
		}
	let A=0;
	let B=0;
		let Anl=270;
		let Anr=270;
		let Anll=0;
		let Anrr=0;
	@MainLoop
	{
			if(ppp>0){ppp--;}
		SetCommonData("pppCount",ppp);
		SetCommonData("sw_gCount",sw_g);
		SetCommonData("t_pCount",t_ppp);
	let Angl=157.5;
	let Angr=157.5;
	if(GetCommonData("jiki")==1){
	SetSpeed(3.5,2);
	kntu=6;
	}
	if(GetCommonData("jiki")==2){
	SetSpeed(4,2);
	kntu=12;
	}
	if(GetCommonData("jiki")==3){
	SetSpeed(3,2);
	kntu=1;
	}


		//悳ppxvZƂ
		if(GetCommonData("jiki")==2){
		if(GetKeyState(VK_RIGHT)==KEY_HOLD&&Anl<270+90){
		Anrr+=0.5;
		Anl+=0.5;
		}
		else{
		if(Anl>270){
		Anrr-=0.5;
		Anl-=0.5;
		}
		}
		if(GetKeyState(VK_LEFT)==KEY_HOLD&&Anr>270-90){
		Anll-=0.5;
		Anr-=0.5;
		}
		else{
		if(Anr<270){
		Anll+=0.5;
		Anr+=0.5;
		}
		}
		}

	swx=GetPlayerX+cos(sw_r+270)*40;
	swy=GetPlayerY+sin(sw_r+270)*40;
	swa=GetGapAngle(GetPlayerX,GetPlayerY,swx,swy);
		S++;

		k1=cos(10*(S/3))*24;
		k2=sin(10*(-S/3))*18;
		k3=sin(10*(S/3))*18;
		k4=cos(10*(S/3))*5;
			sp=0.32;
		if((GetKeyState(VK_BOMB)==KEY_PULL) && GetCommonData("NoShot")==0)
		{
		if(GetCommonData("jiki")==1){
		kai(40);
		}
		if(GetCommonData("jiki")==2){
		kai(60);
		}
		if(GetCommonData("jiki")==3){
		kai(20);
		}
		}
		if((GetKeyState(VK_BOMB)==KEY_HOLD||sw_bNextShot==true)&&sw_shotCount==-1 && GetCommonData("NoShot")==0 && sw_g>0)
		{
		if(GetCommonData("jiki")==1){
		if(sw_g>=0){sw_g-=1.4;}
		}
		if(GetCommonData("jiki")==2){
		if(sw_g>=0){sw_g-=1.6;}
		}
		if(GetCommonData("jiki")==3){
		if(sw_g>=0){sw_g-=1.2;}
		}
		}
		else {
		if(sw_g<=100 && kaif==1 && GetKeyState(VK_BOMB)==KEY_FREE){
		if(GetCommonData("jiki")==1){
		sw_g+=0.5;
		}
		if(GetCommonData("jiki")==2){
		sw_g+=0.8;
		}
		if(GetCommonData("jiki")==3){
		sw_g+=0.3;
		}
		}
		if(sw_g>100){
		sw_g=100;
		}
		if(sw_g<=0){
		sw_g=0;
		}
		}
		
		if((GetKeyState(VK_BOMB)==KEY_PUSH || GetKeyState(VK_BOMB)==KEY_HOLD || sw_bNextShot==true) && sw_shotCount==-1 && GetCommonData("NoShot")==0)
		{
			sw_shotCount = 0;
			sw_bNextShot = false;
		}
		if(GetKeyState(VK_BOMB)==KEY_HOLD && sw_shotCount>0)
		{
			sw_bNextShot = true;
		}
			if(sw_shotCount%3 == 0)
			{
			if(sw_g>=1){
	PlaySE(shot1);
	if(GetCommonData("jiki")==1){
			loop(4){
			A+=90;
			Shot_j(swx+cos(2.5*S+A)*28+4,swy+sin(2.5*S+A)*28,22,swa+sin(2.5*S+A-sw_r-270)*8,5);
			Shot_j(swx+cos(2.5*S+A)*28-4,swy+sin(2.5*S+A)*28,22,swa+sin(2.5*S+A-sw_r-270)*8,5);
			}
	}
	if(GetCommonData("jiki")==2){
			A=157.5;
			loop(4){
			A+=45;
			Shot_j(GetPlayerX+cos(A)*24,GetPlayerY+sin(A)*24-10,22,270,5);
			}
	}
	if(GetCommonData("jiki")==3){
			A=195;
			loop(4){
			A+=30;
			B=A;
			loop(3){
			B+=120;
			Shot_j(GetPlayerX+cos(A)*64+(cos(B)*20),GetPlayerY+sin(A)*48+(sin(B)*20)+10,22,A,5);
			}
			}
	}
			}
			}
		if(sw_shotCount >= 0)
		{
			sw_shotCount++;
		}
		if(sw_shotCount == 2)
		{
			sw_shotCount=-1;
		}


		if((GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD || bNextShot==true) && shotCount==-1)
		{
			shotCount = 0;
			bNextShot = false;
		}
		if(GetKeyState(VK_SHOT)==KEY_HOLD && shotCount>0)
		{
			bNextShot = true;
		}

		let ttt=k4;
			if(shotCount%3 == 0)
			{
	if(GetCommonData("jiki")==1){
			CreatePlayerShot01(GetPlayerX(), GetPlayerY(), 25, 270, sp, 3, 4);
			CreatePlayerShot01(GetPlayerX()+k1-k3, GetPlayerY()-k2-10, 24, 270+ttt, sp, 4, 3);
			CreatePlayerShot01(GetPlayerX()-k1+k3, GetPlayerY()+k2-10, 24, 270-ttt, sp, 4, 3);
			CreatePlayerShot01(GetPlayerX()+k1+k3, GetPlayerY()-k2-10, 24, 270+ttt, sp, 4, 3);
			CreatePlayerShot01(GetPlayerX()-k1-k3, GetPlayerY()+k2-10, 24, 270-ttt, sp, 4, 3);
			CreatePlayerShot01(GetPlayerX()+k1, GetPlayerY()-k2-10, 24, 270+ttt, sp, 4, 3);
			CreatePlayerShot01(GetPlayerX()-k1, GetPlayerY()+k2-10, 24, 270-ttt, sp, 4, 3);
	}
	if(GetCommonData("jiki")==2){
			CreatePlayerShot01(GetPlayerX(), GetPlayerY(), 25, 270, sp, 3, 4);
			loop(4){
			Angr+=45;
			Angl+=45;
			CreatePlayerShot01(GetPlayerX+50+cos(Angr+Anrr)*20,GetPlayerY+20+sin(Angr+Anrr)*20,24,Anl,sp+0.1,4,3);
			CreatePlayerShot01(GetPlayerX-50+cos(Angl+Anll)*20,GetPlayerY+20+sin(Angl+Anll)*20,24,Anr,sp+0.1,4,3);
			}
	}
	if(GetCommonData("jiki")==3){
			CreatePlayerShot01(GetPlayerX(), GetPlayerY(), 28, 270, sp, 4, 4);
			CreatePlayerShot01(GetPlayerX()+35, GetPlayerY, 24, 270, sp+0.1, 4, 3);
			CreatePlayerShot01(GetPlayerX()-35, GetPlayerY, 24, 270, sp+0.1, 4, 3);
			CreatePlayerShot01(GetPlayerX()+25, GetPlayerY, 24, 270, sp+0.1, 4, 3);
			CreatePlayerShot01(GetPlayerX()-25, GetPlayerY, 24, 270, sp+0.1, 4, 3);
	}
		}
		
		if(shotCount >= 0)
		{
			shotCount++;
		}
		if(shotCount == 2)
		{
			shotCount=-1;
		}
		SetGrazeCircle(48);
		SetIntersectionCircle(GetPlayerX,GetPlayerY,1);

	yield;
	}

	task kai(t){
		loop(t){
			yield;
			kaif=0;
		}
		kaif=1;
	}

task Shot_j(x,y,speed,angle,bullet){

	let obj_js=Obj_Create(OBJ_SHOT);
	Obj_SetX(obj_js,x);
	Obj_SetY(obj_js,y);
	Obj_SetSpeed(obj_js,speed);
	Obj_SetAngle(obj_js,angle);
	ObjShot_SetGraphic(obj_js,bullet);
	ObjShot_SetDamage(obj_js,0.3);
	ObjShot_SetPenetration(obj_js,8);
	loop{
	if(Obj_GetY(obj_js)<iy||Obj_GetX(obj_js)<ix||Obj_GetX(obj_js)>mx){
	Obj_Delete(obj_js);
	break;
	}
	if(GetEnemyShotCountEx(Obj_GetX(obj_js),Obj_GetY(obj_js),16,ALL)>0){
	p_m=GetEnemyShotCountEx(Obj_GetX(obj_js),Obj_GetY(obj_js),16,ALL)*2;
	ppp+=p_m;
	t_ppp+=p_m;
	AddGraze(p_m);
	AddScore(ppp);
	DeleteEnemyShotToItemInCircle(SHOT,Obj_GetX(obj_js),Obj_GetY(obj_js),12);
	ObjShot_SetGraphic(obj_js,7);
	Obj_SetSpeed(obj_js,4);
	Obj_SetAngle(obj_js,angle+rand(12,-12));
	ObjShot_SetDamage(obj_js,1);
	ObjShot_SetPenetration(obj_js,20);
	loop(6){
	p_m=GetEnemyShotCountEx(Obj_GetX(obj_js),Obj_GetY(obj_js),kntu,ALL)*2;
	ppp+=p_m;
	t_ppp+=p_m;
	AddGraze(p_m);
	AddScore(ppp);
	DeleteEnemyShotToItemInCircle(SHOT,Obj_GetX(obj_js),Obj_GetY(obj_js),kntu-1);
	yield;
	}
	Obj_Delete(obj_js);
	return;
	}
	yield;
	}


}

function GetGapAngle(
	let xA,
	let yA,
	let xB,
	let yB
){
	return atan2( yB - yA, xB - xA );
}

	@SpellCard
	{
	}
	


	let hdn=0;
	let hdn1=0;


	@DrawLoop
	{
	let swo=0;
		SetColor(255, 255, 255);
		SetRenderState(ALPHA);
		SetTexture(imgpsy);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetGraphicAngle(0,0,0);
		if(GetKeyState(VK_LEFT)==KEY_PUSH||GetKeyState(VK_LEFT)==KEY_HOLD)
		{
		if(GetCommonData("jiki")==1){
			SetGraphicRect(1, 133, 49, 188);
			}
		if(GetCommonData("jiki")==2){
			SetGraphicRect(175, 45, 196, 90);
			}
		if(GetCommonData("jiki")==3){
			SetGraphicRect(140, 45, 175, 90);
			}
		}
		else if(GetKeyState(VK_RIGHT)==KEY_PUSH||GetKeyState(VK_RIGHT)==KEY_HOLD)
		{
		if(GetCommonData("jiki")==1){
			SetGraphicRect(1, 69, 49, 124);
			}
		if(GetCommonData("jiki")==2){
			SetGraphicRect(175, 90, 196, 136);
			}
		if(GetCommonData("jiki")==3){
			SetGraphicRect(140, 90, 175, 136);
			}
		}
		else 
		{
		if(GetCommonData("jiki")==1){
			SetGraphicRect(1, 5, 49, 60);
			}
		if(GetCommonData("jiki")==2){
			SetGraphicRect(175, 0, 196, 45);
			}
		if(GetCommonData("jiki")==3){
			SetGraphicRect(140, 0, 175, 45);
			}
		}
		DrawGraphic(GetPlayerX(), GetPlayerY());

		//IvV
		SetColor(255, 255, 255);
		SetRenderState(ALPHA);
		SetTexture(imgpsy);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetGraphicAngle(0,0,S*2);
	if(GetCommonData("jiki")==1){
		SetGraphicRect(100, 100, 117, 117);
		DrawGraphic(GetPlayerX+k1, GetPlayerY-k2-10);
		DrawGraphic(GetPlayerX-k1, GetPlayerY+k2-10);
	}
	if(GetCommonData("jiki")==2){
		SetGraphicRect(100, 140, 117, 157);
		DrawGraphic(GetPlayerX+50,GetPlayerY+20);
		DrawGraphic(GetPlayerX-50,GetPlayerY+20);
	}
	if(GetCommonData("jiki")==3){
		SetGraphicRect(100, 120, 117, 137);
		DrawGraphic(GetPlayerX+30, GetPlayerY);
		DrawGraphic(GetPlayerX-30, GetPlayerY);
	}

		//TuEF|
		SetColor(255, 255, 255);
		SetRenderState(ALPHA);
		SetTexture(imgpsy);
		SetGraphicScale(0.8,0.8);
		SetAlpha(120);
		SetGraphicAngle(0,0,S*3);
	if(GetCommonData("jiki")==1){
		swo=0;
		loop(4){
		swo+=90;
		SetGraphicRect(100, 100, 117, 117);
		DrawGraphic(swx+cos(2.5*S+swo)*28,swy+sin(2.5*S+swo)*28);
		}
	}
	if(GetCommonData("jiki")==2){
		swo=157.5;
		loop(4){
		swo+=45;
		SetGraphicRect(100, 140, 117, 157);
		DrawGraphic(GetPlayerX+cos(swo)*24,GetPlayerY+sin(swo)*24-10);
		}
	}
	if(GetCommonData("jiki")==3){
		swo=195;
		loop(4){
		swo+=30;
		SetGraphicRect(100, 120, 116, 136);
		DrawGraphic(GetPlayerX+cos(swo)*64,GetPlayerY+sin(swo)*48+10);
		}
	}

		//
		SetColor(255, 255, 255);
		SetRenderState(ALPHA);
		SetTexture(imgpsy);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetGraphicAngle(S*4+90,0,-45);
		SetGraphicRect(100, 160, 125, 185);
		DrawGraphic(GetPlayerX, GetPlayerY);
		SetColor(255, 255, 255);
		SetRenderState(ALPHA);
		SetTexture(imgpsy);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetGraphicAngle(0,S*4,45);
		SetGraphicRect(100, 160, 125, 185);
		DrawGraphic(GetPlayerX, GetPlayerY);



	loop(10){
	B1=S+D1;
	A1=sin(B1);
	if(A1>0&&sin(B1*2)>0){
	SetGraphicRect(96,0,140,44);
	SetRenderState(ALPHA);
	SetGraphicScale(1.3*A1,1.3*A1);
	SetAlpha((70*sin(B1*2)));
	SetGraphicAngle(0,0,D1);
	SetTexture(imgpsy);
	DrawGraphic(GetPlayerX, GetPlayerY);
	}
	D1+=36;
	}

	}


	
	@Finalize
	{
		DeleteGraphic(imgpsy);
	}
}
